package com.freight.base.controller;

import com.freight.base.entity.City;
import com.freight.base.service.CityService;
import com.freight.base.vo.AreaCityVo;
import com.freight.base.vo.CityListVo;
import com.freight.base.vo.CityVo;
import com.freight.core.base.FreightLessBaseController;
import com.freight.core.common.annotation.SecretAnnotation;
import com.freight.core.common.utils.PageUtil;
import com.freight.core.common.utils.ResultUtil;
import com.freight.core.common.vo.PageVo;
import com.freight.core.common.vo.Result;
import com.freight.core.common.vo.SearchVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author huyingtai
 */
@Slf4j
@RestController
@Api(description = "城市维表管理接口")
@RequestMapping("/freight/city")
@Transactional
public class BaseCityController extends FreightLessBaseController<City, Long> {

    @Autowired
    private CityService cityService;

    @Override
    public CityService getService() {
        return cityService;
    }

    @RequestMapping(value = "/getAreaCityList", method = RequestMethod.POST)
    @ApiOperation(value = "根据code获取列表")
    public Result<List<AreaCityVo>> getAreaCityList(String code, String type) {

        List<AreaCityVo> page = cityService.getAreaCityList(code,type);
        return new ResultUtil<List<AreaCityVo>>().setData(page);
    }

    @RequestMapping(value = "/getCityList", method = RequestMethod.POST)
    @ApiOperation(value = "根据城市code获取列表")
    public Result<List<CityListVo>> getCityList(String code) {

        List<CityListVo> page = cityService.getCityList(code);
        return new ResultUtil<List<CityListVo>>().setData(page);
    }

    @RequestMapping(value = "/getByCondition", method = RequestMethod.GET)
    @ApiOperation(value = "多条件分页获取")
    @SecretAnnotation(encode = true,decode = true)
    public Result<Page<City>> getByCondition(City city, SearchVo searchVo, PageVo pageVo) {

        Page<City> page = cityService.findByCondition(city, searchVo, PageUtil.initPage(pageVo));
        return new ResultUtil<Page<City>>().setData(page);
    }

    @RequestMapping(value = "/getCityVoLevel", method = RequestMethod.GET)
    @ApiOperation(value = "获取城市")
    @SecretAnnotation(encode = true,decode = true)
    public Result<CityVo> getCityVoLevel(String cityCode) {
        CityVo cityVo = cityService.getCityVoLevel(cityCode);
        return new ResultUtil<CityVo>().setData(cityVo);
    }

}
